package cqcvc.edu.cn.base;

import java.sql.Connection;
import java.sql.DriverManager;

public class BaseDao {
    private static Connection _connection=null;

    public static Connection getConn()
    {
        if(_connection!=null)
        {
            return _connection;
        }
        else {
            _connection=createConnection();
            return _connection;
        }
    }

    private static Connection createConnection() {
        String url = "jdbc:mysql://localhost:3306/";
        String dbName = "p8";
        String userName = "root";
        String userPasswd = "";
        String dbUrl = url + dbName + "?user=" + userName + "&password=" + userPasswd;
        //String dbUrl = "jdbc:mysql://localhost/sys?user=root&password=&characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true";
        try {
            Class.forName("com.mysql.jdbc.Driver");//jdbc驱动
            Connection conn = DriverManager.getConnection(dbUrl);
           return conn;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
